﻿ #region Disclaimer/Info
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //   File:		Page.Validation.cs
 //   Website:		http://dexterblogengine.com/
 //   Authors:		http://dexterblogengine.com/About.ashx
 //   Rev:		1
 //   Created:		19/01/2011
 //   Last edit:		19/01/2011
 //   License:		GNU Library General Public License (LGPL)
 //   File:            Page.Validation.cs
 //   For updated news and information please visit http://dexterblogengine.com/
 //   Dexter is hosted to Codeplex at http://dexterblogengine.codeplex.com
 //   For any question contact info@dexterblogengine.com
 //
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 #endregion

using Topics.Radical.Validation;

namespace Dexter.Domain.Model {
	public partial class Page {
		public virtual void ValidateForSave ( ) {
			Ensure.That ( Id )
				.Named ( "Id" )
				.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
				.Is ( 0 )
				.WithMessage ( "Invalid page Key" );

			Ensure.That ( Title )
				.Named ( "Title" )
				.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
				.IsNotNullNorEmpty ( )
				.WithMessage ( "Invalid page title" );

			Ensure.That ( FormattedBody )
				.Named ( "FormattedBody" )
				.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
				.IsNotNullNorEmpty ( )
				.WithMessage ( "Invalid page body" );

			if ( Parent != null ) {
				Ensure.That ( Parent.Id )
					.Named ( "Parent.Id" )
					.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
					.IsGreaterThen ( 0 )
					.WithMessage ( "The parent page key is invalid." );
			}
		}

		public virtual void ValidateForUpdate ( ) {
			Ensure.That ( Id )
				.Named ( "Id" )
				.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
				.IsGreaterThen ( 0 )
				.WithMessage ( "Invalid page Key" );

			Ensure.That ( Title )
				.Named ( "Title" )
				.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
				.IsNotNullNorEmpty ( )
				.WithMessage ( "Invalid page title" );

			Ensure.That ( FormattedBody )
				.Named ( "FormattedBody" )
				.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
				.IsNotNullNorEmpty ( )
				.WithMessage ( "Invalid page body" );

			if ( Parent != null ) {
				Ensure.That ( Parent.Id )
					.Named ( "Parent.Id" )
					.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
					.IsGreaterThen ( 0 )
					.WithMessage ( "The parent page key is invalid." );
			}
		}

		public virtual void ValidateForDelete ( ) {
			Ensure.That ( Id )
				.Named ( "Id" )
				.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
				.IsGreaterThen ( 0 )
				.WithMessage ( "Invalid page Key" );
		}
	}
}
